<script language="javascript" src="/static/Admin/tinymce/tinymce.min.js"></script>
<script>
    $(document).ready(function () {
        // 编辑器初始化
        tinymce.init({
            selector:'#prointro_content',
            language:'zh_CN',
            mode:'textareas',
            height:300,
            plugins: [
                "advlist autolink lists link image charmap print preview anchor",
                "searchreplace visualblocks code fullscreen",
                "insertdatetime media table contextmenu paste imagetools wordcount",
                "code"
            ],
            toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code",
        });
    });
</script>
<div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="ntModalLabel" type="{$request}">{:strtoupper($title)}</h4>
        <input type="hidden" id="pro_id" value="{$pro_id}">
    </div>
    <div class="modal-body">
            <div class="row clearfix">
                    <div class="col-md-12 column">
                        <div class="alert alert-dismissable alert-info">
                        <button type="button" class="close">×</button>
                        <p></p>
                        </div>
                    </div>
                </div>
        <div class="row clearfix">
            <div class="col-md-12 column">
                <table class="table table-striped ntTable">
                    <tbody>
                        <tr>
                            <td>{:strtoupper(lang("introduction_type"))}</td>
                            <td>
                                <select id="content_name" class="form-control">
                                    {if isset($prodesc_cat)}
                                    {foreach $prodesc_cat as $k1=>$v1}
                                    <option value="{$v1.id}">{$v1.content}</option>
                                    {/foreach}
                                    {/if}
                                </select>
                            </td>
                            <td>{:strtoupper(lang('language'))}</td>
                            <td>
                                <select id="selectLang" class="form-control">
                                    {if isset($lang_idsArr)}
                                        {foreach $lang_idsArr as $k=>$v}
                                            <option value="{$v.lang}">{$v.content}</option>
                                        {/foreach}
                                    {/if}
                                </select>
                            </td>
                        </tr>
                        <tr>
                           {if isset($prochar)}
                                <td>{:strtoupper(lang("the_role_of_product"))}<span class="required"></span></td>
                                <td colspan="3">
                                <select class="form-control" id="prochar" >
                                    <option value='0'>选择产品</option>
                                    {foreach $prochar as $k2=>$v2}
                                    <option  value="{$v2.id}" {if isset($prochar_id)}{if condition="$prochar_id eq $v2.id"}selected {/if}{/if}> {$v2.prochar_title} </option>
                                    {/foreach}}
                                </select>

                                </td>
                            {/if} 
                        </tr>
                        <tr>
                            <td>{:strtoupper(lang('content'))}</td>
                            <td colspan="3">
                                <textarea id="prointro_content">{if isset($content)}{$content}{/if}</textarea>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span>{:strtoupper(lang('cancel'))}</button>
        <button type="button" class="btn btn-primary save" style="padding-left:24px;padding-right:24px"><span class="glyphicon glyphicon-ok"></span>{:strtoupper(lang('confirm'))}</button>
    </div>
    <script type="text/javascript">
        $('#content_name').change(function(){

            if($('#ntModalLabel').attr('type') == 'edit'){
                var url = '/admin/product/proAddNewJump_introEdit'
            }else{
                var url = '/admin/product/proAddNewJump_introAdd';
            }

            var data={ id:$('#content_name option:selected').val(),
                        prochar_id:$('#prochar option:selected').val(),
                        pro_id:$('#pro_id').val()
                    }
            $.ajax({
                // url: '/admin/product/proAddNewJump_introAjax',
                url: url,
                type: 'post',
                data,
                dataType: 'json',
                success: function (res) {
                    res = JSON.parse(res)
                    if(res.status == 1){
                        if($('#ntModalLabel').attr('type') !== 'add'){
                            tinyMCE.activeEditor.setContent(res.data.content);
                        }
                        $('#selectLang').empty();
                        var lang_html = '';
                        for (var i = 0;i < res.data.length; i++) {
                            lang_html += "<option value='"+res.data[i].lang+"'>"+res.data[i].content+"</option>";
                        }
                        $('#selectLang').append(lang_html);
                    }else{
                        alert(res.msg);
                    }
                }
            })
        });

        $('#selectLang').change(function(){
            if($('#ntModalLabel').attr('type') == 'edit'){
                var url = '/admin/product/proAddNewJump_introEdit'
            }else{
                var url = '/admin/product/proAddNewJump_introAdd';
            }
            $.ajax({
                // url: '/admin/product/proAddNewJump_introAjax',
                url: url,
                type: 'post',
                data: { 
                        id:$('#content_name option:selected').val(),
                        lang:$('#selectLang option:selected').val(),
                        prochar_id:$('#prochar option:selected').val(),
                        pro_id:$('#pro_id').val()
                    },
                dataType: 'json',
                success: function (res) {
                    res = JSON.parse(res)
                    if(res.status == 1){
                        if($('#ntModalLabel').attr('type') !== 'add'){
                            tinymce.activeEditor.setContent(res.data.content);
                        }
                    }else{
                        alert(res.msg);
                    }
                }
            })
        });

        $('#prochar').change(function(){
            if($('#ntModalLabel').attr('type') == 'edit'){
                var url = '/admin/product/proAddNewJump_introEdit'
            }else{
                var url = '/admin/product/proAddNewJump_introAdd';
            }
            $.ajax({
                // url: '/admin/product/proAddNewJump_introAjax',
                url: url,
                type: 'post',
                data: { 
                        id:$('#content_name option:selected').val(),
                        lang:$('#selectLang option:selected').val(),
                        prochar_id:$('#prochar option:selected').val(),
                        pro_id:$('#pro_id').val(),
                    },
                dataType: 'json',
                success: function (res) {
                    res = JSON.parse(res)
                    if(res.status == 1){
                        if($('#ntModalLabel').attr('type') !== 'add'){
                            tinymce.activeEditor.setContent(res.data.content);
                        }
                    }else{
                        alert(res.msg);
                    }
                }
            })
        });

        $('.save').click(function(){
            if($('#ntModalLabel').attr('type') == 'edit'){
                var url = '/admin/product/proAddNewJump_introEdit?request=update'
            }else{
                var url = '/admin/product/proAddNewJump_introAdd?request=insert';
            }
            $.ajax({
                url: url,
                type: 'post',
                data: {
                        id:$('#content_name option:selected').val(),
                        lang:$('#selectLang option:selected').val(),
                        content:tinymce.activeEditor.getContent(),
                        pro_id:$('#pro_id').val(),
                        prochar_id:$('#prochar option:selected').val(),
                    },
                dataType: 'json',
                success: function (data) {
                    data = JSON.parse(data)
                    if(data.status==1){
                        change_mes_type('.alert',data.status)
                        $('.alert').show()
                        $('.alert p').html('*'+data.msg+'<br>')
                          //toastr.info(data.msg)
                          $('#prointro_editModal').modal('hide')
                          /* setTimeout(function(){
                              location.reload();
                          },1000) */
                      }else{
                        change_mes_type('.modal-body .alert',data.status)
                        $('.modal-body .alert').show()
                        $('.modal-body .alert p').html('*'+data.msg+'<br>')
                         // toastr.warning(data.msg);
                      }
                }
            })
        });
    </script>